<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f4;
        margin: 0;
        padding: 20px;
    }
    h1 {
        text-align: center;
        color: #333;
    }
    table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
        background-color: #fff;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    th, td {
        padding: 15px;
        text-align: left;
        border-bottom: 1px solid #ddd;
    }
    th {
        background-color: #4CAF50;
        color: white;
    }
    tr:hover {
        background-color: #f5f5f5;
    }
    .navbar {
        margin-bottom: 20px;
        text-align: center;
    }
    .navbar a {
        margin: 0 10px;
        text-decoration: none;
        color: #007bff;
        font-weight: bold;
    }
    .navbar a:hover {
        text-decoration: underline;
    }
    .edit-button {
        text-decoration: none;
        color: #28a745;
        font-weight: bold;
        margin-right: 10px; /* 添加右边距 */
    }
    .edit-button:hover {
        text-decoration: underline;
    }
    .view-button {
        text-decoration: none;
        color: #007bff;
        font-weight: bold;
        margin-left: 10px; /* 添加左边距 */
    }
    .view-button:hover {
        text-decoration: underline;
    }
    .pagination {
        display: flex;
        justify-content: center;
        margin-top: 20px;
    }
    .pagination a, .pagination span {
        margin: 0 5px;
        text-decoration: none;
        color: #007bff;
        font-weight: bold;
        padding: 5px 10px;
        border: 1px solid #ddd;
        border-radius: 5px;
    }
    .pagination a:hover, .pagination span:hover {
        text-decoration: underline;
        background-color: #f5f5f5;
    }
    .pagination .current-page {
        background-color: #007bff;
        color: white;
        border-color: #007bff;
    }
</style>
</head>
<body>
<div class="navbar">
    <a href="{{ url_for('new_ticket') }}">New Ticket</a>
    <a href="{{ url_for('report') }}">Daily Report</a>
    <a href="{{ url_for('logout') }}">Logout</a>
</div>
    <h1>Dashboard</h1>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <!-- <th>Content</th> -->
                <th>Category</th>
                <th>Assignee</th>
                <th>Status</th>
                <th>Created</th>
                <th>Creator</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for ticket in tickets %}
            <tr>
                <td>{{ ticket.id }}</td>
                <td>{{ ticket.name }}</td>
                <!-- <td>{{ ticket.content }}</td> -->
                <td>{{ ticket.category }}</td>
                <td>{{ ticket.assignee }}</td>
                <td>{{ ticket.status }}</td>
                <td>{{ ticket.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                <td>{{ ticket.creator }}</td>
                <td>
                    <a href="{{ url_for('edit_ticket', ticket_id=ticket.id) }}" class="edit-button">Edit</a>
                    <a href="{{ url_for('view_ticket', ticket_id=ticket.id) }}" class="view-button">View</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <div class="pagination">
        {% if pagination.has_prev %}
            <a href="{{ url_for('dashboard', page=pagination.prev_num, per_page=pagination.per_page) }}">Previous</a>
        {% endif %}

        {% for page_num in pagination.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
            {% if page_num %}
                {% if page_num == pagination.page %}
                    <span class="current-page">{{ page_num }}</span>
                {% else %}
                    <a href="{{ url_for('dashboard', page=page_num, per_page=pagination.per_page) }}">{{ page_num }}</a>
                {% endif %}
            {% else %}
                <span class="ellipsis">…</span>
            {% endif %}
        {% endfor %}

        {% if pagination.has_next %}
            <a href="{{ url_for('dashboard', page=pagination.next_num, per_page=pagination.per_page) }}">Next</a>
        {% endif %}

        <a href="{{ url_for('dashboard', page=pagination.pages, per_page=pagination.per_page) }}">Last</a>

        <div>
            <label for="per-page">Per page:</label>
            <select id="per-page" onchange="window.location.href=this.value">
                <option value="{{ url_for('dashboard', per_page=10) }}" {% if pagination.per_page == 10 %}selected{% endif %}>10</option>
                <option value="{{ url_for('dashboard', per_page=20) }}" {% if pagination.per_page == 20 %}selected{% endif %}>20</option>
                <option value="{{ url_for('dashboard', per_page=50) }}" {% if pagination.per_page == 50 %}selected{% endif %}>50</option>
            </select>
        </div>
    </div>
</body>
</html>